import { defineStore } from "pinia";
import router from "@/router";
import { setLocalStorage } from "@/utils/utils";

export const useLoginStore = defineStore("login", {
    state: () => ({
        token: ''
    }),
    actions: {
        setToken(val: string) {
            this.token = val
        },
        logout() {
            setLocalStorage('token','')
            this.token = ''
            router.push('/login')
        }
    },
    persist: {
        enabled: true,
        strategies: [
            {
                key: 'token',
                storage: localStorage
            }
        ]
    }
});